package com.example.server.service;

import com.example.server.gen.GreeterGrpc;
import com.example.server.gen.HelloReply;
import com.example.server.gen.HelloRequest;
import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import org.lognet.springboot.grpc.GRpcService;

/** hello service impl
 *
 * @author yangyang
 * @date 2023/11/30
 */
@GRpcService
@Slf4j
public class HelloServiceImpl extends GreeterGrpc.GreeterImplBase {
 
 
    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
        // 获取客户端发送的请求消息
        String name = request.getName();
        // 构建响应消息
        HelloReply response = HelloReply.newBuilder()
        .setMessage("Hello, Hello," + name + "!")
        .build();
//        log.info("[grpc server]: response: {}", response);
 
        // 发送响应消息
        responseObserver.onNext(response);
        // 通知客户端响应已经完成
        responseObserver.onCompleted();
    }
}